package com.ruoyi.web.controller.prt;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.prt.domain.PrtCouponMode;
import com.ruoyi.prt.service.IPrtCouponModeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 优惠券模板Controller
 *
 * @author xiaobo Yan
 * @date 2021-03-31
 */
@RestController
@RequestMapping("/prt/mode")
public class PrtCouponModeController extends BaseController
{
    @Autowired
    private IPrtCouponModeService prtCouponModeService;

    /**
     * 查询优惠券模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:mode:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrtCouponMode prtCouponMode)
    {
        startPage();
        List<PrtCouponMode> list = prtCouponModeService.selectPrtCouponModeList(prtCouponMode);
        return getDataTable(list);
    }

    /**
     * 导出优惠券模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:mode:export')")
    @Log(title = "优惠券模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PrtCouponMode prtCouponMode)
    {
        List<PrtCouponMode> list = prtCouponModeService.selectPrtCouponModeList(prtCouponMode);
        ExcelUtil<PrtCouponMode> util = new ExcelUtil<PrtCouponMode>(PrtCouponMode.class);
        return util.exportExcel(list, "mode");
    }

    /**
     * 获取优惠券模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:mode:query')")
    @GetMapping(value = "/{couponModeId}")
    public AjaxResult getInfo(@PathVariable("couponModeId") String couponModeId)
    {
        return AjaxResult.success(prtCouponModeService.selectPrtCouponModeById(couponModeId));
    }

    /**
     * 新增优惠券模板
     */
    @PreAuthorize("@ss.hasPermi('system:mode:add')")
    @Log(title = "优惠券模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrtCouponMode prtCouponMode)
    {
        return toAjax(prtCouponModeService.insertPrtCouponMode(prtCouponMode));
    }

    /**
     * 修改优惠券模板
     */
    @PreAuthorize("@ss.hasPermi('system:mode:edit')")
    @Log(title = "优惠券模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrtCouponMode prtCouponMode)
    {
        return toAjax(prtCouponModeService.updatePrtCouponMode(prtCouponMode));
    }

    /**
     * 删除优惠券模板
     */
    @PreAuthorize("@ss.hasPermi('system:mode:remove')")
    @Log(title = "优惠券模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{couponModeIds}")
    public AjaxResult remove(@PathVariable String[] couponModeIds)
    {
        return toAjax(prtCouponModeService.deletePrtCouponModeByIds(couponModeIds));
    }
}
